<!DOCTYPE html>
<html>
<head>
	<title>杂物检测</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title></title>
    <script src="js/mui.js"></script>
	<script src="js/layui/layui.all.js"></script>
    <link href="css/mui.css" rel="stylesheet"/>
	<link href="css/common.css" rel="stylesheet"/>
	<link href="css/gnxz.css" rel="stylesheet"/>
    <link href="css/xmjc.css" rel="stylesheet"/>
    <script type="text/javascript" src="js/common.js" ></script>
	<script type="text/javascript" src="js/function.js" ></script>
    
    <!-- Nicky -->
    <link rel="stylesheet" href="css/nicky.css" /> 
    <script src="js/jquery.min.js"></script>
    <script src="js/webdb.js"></script>
</head>
<body>
	  
		<header class="mui-bar mui-bar-nav mui-bar-transparent bg main-header" >
		<div class="back"><a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left back" >返回</a></div> 
	   </header>
	   <div class="bg main-nav" > </div>
	   
	   <div class="mui-content" style="margin-top:20px;" >
	   		<div class="pBox">
				<div class="pHeader" >杂物检测</div>
				<div class="uinfo" >
					<ul>
					  <li><i>磅单号:</i><b class="txtBdid"></b></li>
					  <li><i>车牌号:</i><b class="txtCarnum"></b></li>
				    </ul>
				</div>
		   	</div>

		    <div id="dataList" class="dataList dataList2">
				<dl>
					<!--<dd>
						<em>1</em>
						<p>
							<span><b>包重</b><i>120</i></span>
							<span><b>杂物重量</b><i>23/45</i></span>
							<span><b>杂物比例</b><i>20%</i></span>
							<span class="u"><b>质检员</b><i>12345/张三丰</i></span>
							<span><b>上传人</b><i>12</i></span>
							<span><b>备注</b><i>备注信息</i></span>
						</p>
						<i></i>
					</dd>-->
				</dl>
     			<div class="cc"></div>
	         	<br ><br ><br >
			 </div> 

	   </div>
	   <div class="btnBox fixBottom">
	  		<button class="nbtn disable" id="tnUpload">提交</button>
	  		<!--<button class="nbtn disable" id="tnSave">保存</button>-->
	  		<button class="nbtn disable" id="btnAdd">添加</button>
	  		<button class="nbtn disable" id="btnDel">删除</button>
	  		<button class="nbtn disable mySwitch" id="btnRepeat" >复检</button>
	  	</div>
	  	
	  <script>
		var uid = null, uinfo = null, serverData=null , rowid = 0;
		mui.init();
		mui.plusReady(function(){
			uid = getSession('UID');
			uinfo = JSON.parse(getSession('UINFO'));
			serverData = JSON.parse(getSession('serData')); 
			$('.txtBdid').text(serverData.bdid); 
			$('.txtCarnum').text(serverData.carNum);
			
			checkUserRose(); 
			getZWData();
			
			//提交
			$('#tnUpload').click(function(){ });
			//保存
	  		$('#tnSave').click(function(){});
	  		//添加
	  		$('#btnAdd').click(function(){ mui.openWindow({ url:'zwjc_add.html' }); });
	  		//删除
	  		$('#btnDel').click(function(){ 
				if($("#delete").hasClass('disable')){ return false;}
				if($('.dataList dl dd.sel').length<1){
					plus.nativeUI.toast('请选择要删除的数据');
				}else{
					plus.nativeUI.showWaiting("正在删除");
					$('.dataList dl dd.sel').remove();
					setTimeout(function(){ plus.nativeUI.closeWaiting(); },2000);
				}
			});
	  		//复检
	  		$('#btnRepeat').click(function(){ 
		  		if($(this).hasClass('hasset')){
				  	$(this).removeClass('hasset');
				    $('.dataList dl dd>i').remove();
				}else{
				  	$(this).addClass('hasset');
				    $('.dataList dl dd').append('<i></i>');
				}
	  		});
		})


function getZWData(){
	var where = {ZJNUM:uid};
	select('zw',TBS.zw,{where:where},function(dat){
		if(dat.length){
			var html = '';
			for(i=0;i<dat.length;i++){
				html += getLineHtml(i+1,dat.item(i));
				rowid = i+1;
			}
			$('#dataList dl').html(html);
		}
	});
	initListClick();
}

function getLineHtml(i,dat){
	var html = '<dd rowid="'+i+'"><em>'+i+'</em><p>'
				+'<span><b>包重</b><i>'+dat.ZJDBZ+'</i></span>'
				+'<span><b>杂物重量</b><i>'+dat.ZCLJG+'</i></span>'
				+'<span><b>杂物比例</b><i>'+dat.ZJSBL+'</i></span>'
				+'<span class="u"><b>质检员</b><i>'+dat.ZWZBY+'</i></span>'
				+'<span><b>上传人</b><i>'+dat.ZJNUM+'</i></span>'
				+'<span><b>备注</b><i>'+dat.BZTX+'</i></span>'
				+'</p></dd>';
	return html;
}

/*
BD_NO:磅单号
ITEM:行项目，回传SAP接口固定值"10"
BITEM:项目号
ZWZFL:"ZW"杂物
ZLYFS:来源方式，回传SAP接口固定值"A"
ZJNUM:上传人，用户表中的ID字段
ZWZBY:质检员，数据格式为“质检员编号\质检员姓名”，例："1\张三"
ZCLJG:杂物重量
ZJDBZ:包重
ZJSBL:杂物比例
ZFJBZ:是否复检，复检为"X"
BZTXT:备注
*/

function addItemToDB(baozhong,zawuzhong){
	var dat = {BD_NO:serverData.bdid,ITEM:10,BITEM:0,ZWZFL:'ZW',ZLYFS:'A',ZJNUM:uid,ZWZBY:'12/质检员',ZCLJG:baozhong,ZJDBZ:zawuzhong,ZJSBL:zawuzhong/baozhong,ZFJBZ:'',BZTXT:'备注'};
	var row = [];
	$.each(dat, function(i,d) {
		row.push(d);
	});
	insert('zw',TBS.zw,row);
	var html = getLineHtml(rowid++,dat);
	$('#dataList dl').append(html); 
	initListClick();
}

function initListClick(){ 
	mui(".dataList dl").off();
	mui(".dataList dl").on('tap','dd',function(){ 
		if($(this).hasClass('sel')){
			//修改
			mui.openWindow({ url:'zwjc_add.html',extras:{rowid:this.getAttribute('rowid')} });
		}else{
			$('.dataList dl dd.sel').removeClass('sel');
			$(this).addClass('sel');
		}
	});
}

function checkUserRose(){ 
	//G 用户管理员，     Z 质检员 无删除复检权限，      B 班长 有删除无复检权限，     F 复检员
	if('G'==uinfo.USERS1){
		
	}else if('B'==uinfo.USERS1){
		$("#tnUpload,#tnSave,#btnAdd,#btnDel,#btnRepeat").removeClass('disable'); 
	}else if('F'==uinfo.USERS1){
		$("#btnRepeat").removeClass('disable');
	}
}
	  </script>
</body>
</html>